/*============================================================================
  File:      IDMAlgorithmFactory.Stubs.cpp
 
  Summary:   IDMAlgorithmFactory implementation to paste into implementation 
			 file for your factory class

  Date:		 September 12, 2003
------------------------------------------------------------------------------
  This file is part of the Microsoft SQL Server Code Samples.
 
  Copyright (C) 2003 Microsoft Corporation.  All rights reserved.
 
This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.
 
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
============================================================================*/

// IDMAlgorithmFactory

STDMETHODIMP	YOUR_FACTORY_CLASS::CreateAlgorithm(IDMModelServices*	in_pContext,
                                                    IDMAlgorithm**		out_ppAlgorithm)
{
	// Assuming that your algorithm derives from the class DMHALLOC, we use
	// the ATL extensions in DmhMemory.h to create new instances. By deriving
	// from DMHALLOC, your algorithm can allocate memory using the model-services
	// memory allocator by simply passing a reference to itself on any new()
	// call.

	CComObjectDM<YOUR_ALG_CLASS>*	pAlgo;
	
	DMHALLOC	dmhalloc;

	dmhalloc.SetAllocator(in_pContext);

	HRESULT hr = CComObjectDM<YOUR_ALG_CLASS>::CreateInstance(dmhalloc, &pAlgo);

	if (SUCCEEDED(hr) && pAlgo)
	{
		return pAlgo->QueryInterface(__uuidof(IDMAlgorithm), (void**)out_ppAlgorithm);
	}

	return hr;
}